﻿
Ext.ns('SafeBox.Store');

SafeBox.Store.CredentialStore = Ext.extend(Ext.data.Store, {
    storeId: 'SafeBox.Store.CredentialStore',
    autoload: true,
    autoSave: true,
    listeners: {
        datachanged: function () {
            this.save();
        }
    },
    get: function () {
        var _list = [];
        for (i = 0; i < this.data.length; i++) {
            _list.push(this.data.items[i].data);
        }
        return _list;
    },
    remove: function (id) {
        var _index = this.findExact('id', id);
        if (_index != -1) {
            this.removeAt(_index);
            this.sync();
        }
    },
    edit: function (id, detail) {
        var _index = this.findExact('id', id);
        if (_index != -1) {
            var _r = this.getAt(_index);
            _r.data.name = detail.name;
            _r.data.link = detail.link;
            _r.data.icon = detail.icon;
            _r.data.user = detail.user;
            _r.data.password = detail.password;
            _r.data.desciption = detail.desciption;
            _r.data.category = detail.category;
            _r.data.empty = false;

            _r.setDirty();
            _r.save();
            this.sync();
        }
    }
});